﻿using System;
using System.Windows.Data;
using System.Windows.Media;
using IssueVision.EntityModel;

namespace IssueVision.Common
{
    /// <summary>
    /// One way IValueConverter that returns a SolidColorBrush based on Issue.Priority
    /// </summary>
    public class IssueBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            SolidColorBrush brush;

            if (((Issue)value).ResolutionID == null || ((Issue)value).ResolutionID == 0)
            {
                switch (((Issue)value).Priority)
                {
                    case 1:
                        brush = new SolidColorBrush(Colors.Red);
                        break;
                    case 2:
                        brush = new SolidColorBrush(Colors.Orange);
                        break;
                    case 3:
                        brush = new SolidColorBrush(Colors.Blue);
                        break;
                    case 4:
                        brush = new SolidColorBrush(Colors.Green);
                        break;
                    default:
                        brush = new SolidColorBrush(Colors.White);
                        break;
                }
                brush.Color = new Color { A = (byte)(brush.Color.A / 2), B = brush.Color.B, G = brush.Color.G, R = brush.Color.R };
                return brush;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}